<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}ui.css" />
<link rel="Stylesheet" href="${aier_css_url}jq/jq.css" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}text.css" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}enhanced.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}proxy/ac.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}custominput.js"></script>
<script type="text/javascript" src="${aier_js_url}${aier_jqui_js}text.js"></script>
<title>分派卡</title>
</head>
<script type="text/javascript">
	$(document).ready(
			function() {
			$("#iccardsinfo").jqGrid(
						{
							datatype : "local",
							height:'230',
							width:'600',  
							//getData:{'ruid':-1},               
							colNames : [ 'IC卡编号', 'icid' ],
							colModel : [ 
							{name : 'icName',index : 'icName',width : 500
							},
							{name : 'icid',index : 'icid',hidden : true
							} ],
							
							pager : jQuery("#iccardspage"),
	
							rowNum : 10,
							//rowList: [10, 20, 30],
							sortname : 'icName',
							hidegrid : false,
							sortorder : 'asc',
							viewrecords : true,
							caption : '可用IC卡信息',
							gridComplete : function() {
								var ids = jQuery("#iccardsinfo").jqGrid('getDataIDs');
								for ( var i = 0; i < ids.length; i++) {
									var id = ids[i];

									jQuery("#iccardsinfo").jqGrid('setRowData',ids[i]);
								}
							}
						}).navGrid("#iccardspage", {edit : false,add : false,del : false,search : false
				});
		});
//表格加载数据
function loadData(){
	var fun = function(data) {
			if (10001 == data.s) {
				for(var i=0;i<data.icCards.length;i++){
					jQuery("#iccardsinfo").jqGrid('addRowData',i,
						{
							icName : data.icCards[i].icName,
							icid : data.icCards[i].icid,
						});
				}
				
			}
		};
		
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}quicksc_serachproxycard${aier_suffix}"),fun, {
			"pid" : "${pid}",
			"ichead" : $("#sel_position").find("option:selected").text(),
			"icbodyMin" : $("#txt_head").val(),
			"icbodyMax" : $("#txt_body").val(),
		});
}
//加载session中的卡号
function assign_load(){
	var fun = function(data) {
			if (10001 == data.s&&!isnull(data.mCards)&&0<data.mCards.length) {
				for(var i=0;i<data.mCards.length;i++){
					jQuery("#iccardsinfo").jqGrid('addRowData',i,
						{
							icName : data.mCards[i],
						});
				}
			}else{
				return
			}
		};
		
		exeAjax(ajaxUrl("${aier_url}${aier_urijs}quicksc_assign_load${aier_suffix}"),fun, {
			
		});
}
assign_load();
</script>
<body>
	<div id="tabs">
		<ul>
			<li><a href="#tabs-1">分派IC卡</a>
			</li>
		</ul>
		<div id="tabs-1" style="height: 500px;">
			<div class="d_content">
				<div class="d_scnOut">
					<div class="d_scname">
						<label for="sel_position">分派卡</label>
					</div>
					<div class="sel_region">
						<select id="sel_position" onchange="acSelcardsNum()">

						</select>
					</div>
					<div style="margin-left: 0px;margin-top: 2px;">
						<div class="d_sctext">
							<input type="text" id="txt_head">&nbsp<span>-</span>
						</div>
						<div class="d_sctext"
							style="margin-left: 272px;margin-top: -20px;">
							<input type="text" id="txt_body">
						</div>
					</div>
					<button id="b_acSel" onclick="loadData()"
						style="margin-left: 350px;margin-top: -43px;"
						class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
						role="button" aria-disabled="false">
						<span class="ui-button-text">分派</span>
					</button>
					<div class="d_cardsInfo" id="d_agicNum"
						style="visibility: hidden; ">
						该系列卡还剩<span id="acICNum"></span>张
					</div>
				</div>
				<!-- 表格数据 -->
				<table id="iccardsinfo"></table>
				<div id="iccardspage"></div>

				<button id="but_previous"
					style="margin-left: 300px;margin-top: 20px;"
					class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
					role="button" aria-disabled="false">
					<span class="ui-button-text">上一步</span>
				</button>
				<button id="but_next" style="margin-left: 100px;margin-top:20px;"
					class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
					role="button" aria-disabled="false">
					<span class="ui-button-text">下一步</span>
				</button>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	$("#tabs").tabs();
	$('#but_previous')
			.click(
					function() {
						location.href = "${aier_url}proxy/creates_classesManage${aier_suffix}?pid=${pid}";
					});
	$('#but_next')
			.click(
					function() {
						//获得班级名称
							var gr = jQuery("#iccardsinfo").jqGrid('getRowData');
							var icards = "";
							for ( var i = 0; i < gr.length; i++) {
								if (i == (gr.length - 1)) {
									icards += gr[i].icName;
								} else {
									icards += gr[i].icName + ",";
								}

							}

						var fun = function(data) {
							if (10001 == data.s) {
								location.href = "${aier_url}proxy/creates_bindIcard${aier_suffix}?pid="
										+ data.pid + "";
							}

						};

						exeAjax(
								ajaxUrl("${aier_url}${aier_urijs}quicksc_bind_next${aier_suffix}?pid=${pid}"),
								fun, {
									"icards" : icards,
								});
					});

	acSelichead();

	//获得IC卡前缀
	function acSelichead() {
		var fun = function(data) {
			if (10001 == data.s) {
				var c = data.acard_head;
				if (!isnull(c) && 0 < c.length) {
					for ( var i = 0; i < c.length; i++) {
						$("#sel_position").append(
								"<option>" + c[i] + "</option>");
					}
					acSelcardsNum();
				} else {
					$().message("没有未分配的卡！");
				}

			}
		};
		exeAjax(
				ajaxUrl("${aier_url}${aier_urijs}quicksc_ac_gethead${aier_suffix}"),
				fun, {

					"pid" : "${pid}",
				});
	}
	//获取此种IC卡数量
	function acSelcardsNum() {
		var fun = function(data) {
			if (10001 == data.s) {
				$("#acICNum").html(data.cardsNum);
				$("#d_agicNum").css("visibility", "visible");

			}
		};
		exeAjax(
				ajaxUrl("${aier_url}${aier_urijs}quicksc_serachcardsnum${aier_suffix}"),
				fun, {
					"ichead" : $("#sel_position").find("option:selected")
							.text(),
					"pid" : "${pid}",
				});
	}
</script>
</html>